package com.diandian.CoolCo.schulte;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.View;

public class IndexView extends View{
	
	private Paint paint = new Paint();
	private Path  path  = new Path();
	private float small_radius, big_radius;
	private int   cx, cy;
	private float density;

	public int getCx() {
		return cx;
	}

	public int getCy() {
		return cy;
	}

	public IndexView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		Resources resources = getContext().getResources();
        DisplayMetrics dm = resources.getDisplayMetrics();
		density = dm.density;
	}

	public float getSmall_radius() {
		return small_radius;
	}

	public float getBig_radius() {
		return big_radius;
	}

	public IndexView(Context context, AttributeSet attrs) {
		super(context, attrs);
		Resources resources = getContext().getResources();
        DisplayMetrics dm = resources.getDisplayMetrics();
		density = dm.density;
	}
	
	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		super.onDraw(canvas);
		
		int paddingLeft = getPaddingLeft();
		int paddingTop = getPaddingTop();
		int paddingRight = getPaddingRight();
		int paddingBottom = getPaddingBottom();
		int contentWidth = getWidth() - paddingLeft - paddingRight;
		int contentHeight = getHeight() - paddingTop - paddingBottom;
		cx = contentWidth / 2;
		cy = contentHeight / 2;
		
		double scale = (float) ((float) contentWidth/480 );
		small_radius = (float) (144.2 * scale);
		big_radius   = (float) (166.6 * scale);
//		small_radius = 92 * density;
//		big_radius   = 112 * density;
		
		float stroke_width = (float) (10.5 * scale);
		
		paint.setAntiAlias(true);
		paint.setColor(getResources().getColor(R.color.index));


//		paint.setStrokeWidth(10.5 * circle_scale);
		paint.setStrokeWidth(stroke_width);
		paint.setStyle(Style.STROKE);
		
		canvas.drawCircle(cx, cy, small_radius, paint);
		canvas.drawCircle(cx, cy, big_radius, paint);

		// draw start icon
		paint.setStyle(Style.FILL_AND_STROKE);
//		float triangle_scale = 3;
//		float triangle_width = 30 * triangle_scale;
//		float triangle_height = 40 * triangle_scale;
		float triangle_width = (float) (90 * scale);
		float triangle_height = (float) (120 * scale);
		
		path.setFillType(Path.FillType.EVEN_ODD);
		path.moveTo(cx - triangle_width / 2 + triangle_width/8, cy - triangle_height / 2);
		path.lineTo(cx + triangle_width / 2 + triangle_width/8, cy);
		path.lineTo(cx - triangle_width / 2 + triangle_width/8, cy + triangle_height / 2);
		path.close();
		canvas.drawPath(path, paint);
		
	}
	
}
